import request from '@/utils/request'
// 下载文件
import axios from 'axios'

export function genSearch(query) {
  return request({
    url: '/gen/article/list',
    method: 'get',
    params: query
  })
}

export function genCode(data) {
  axios({
    url: process.env.VUE_APP_BASE_API + '/gen/GenCodeToJava',
    method: 'post',
    responseType: 'blob',
    data
  }).then(res => {
    debugger
    const blob = new Blob([res.data])
    if ('download' in document.createElement('a')) {
      const link = document.createElement('a')
      link.href = window.URL.createObjectURL(blob)
      link.download = data.ClassName + '.zip'
      link.click()
      window.URL.revokeObjectURL(link.href)
    } else {
      navigator.msSaveBlob(blob, 'helloword.txt')
    }
  }).catch(error => {
    console.log('error: ', error)
  })
}
